<?php
namespace app\index\controller;

use app\index\model\doAdmin;
use think\Db;
use app\index\model\doCate;
use app\index\model\doGoods;

use app\index\model\doUser;
use think\facade\Cookie;
use think\facade\Request;

class Index extends Base
{

    // 首页
    public function index()
    {
        $admin = Db::name('admin')->where('id',$this->admin['id'])->find();
        if($admin['first']<1){
            $this->redirect('/index/index/changepassword');
        }
        $this->assign('admin',$this->admin);
        $if_first = 1;
        if($this->admin['lv']==2){
            if(Db::name("admin")->where('area',$this->admin['area'])->count()>2){
                $if_first = 0;
            }
        }
        if($this->admin['lv']==0&&$admin['first']==1){
            
            $if_first = 1;
            
        }
        if($this->admin['rid']==8){
            if(Db::name("school_renzheng")->where("admin_id",$this->admin['id'])->find()){
               $this->assign('if_rz',1); 
            }else{
                $this->assign('if_rz',0);
            }
            
        }else{
            
        }
        $this->assign('admin',$this->admin);
        $this->assign('if_first',$if_first);
        return $this->fetch();
    }

    // 欢迎页
    public function welcome()
    {
        $admin = $this->admin;

        $cate = doCate::count('id');
        $goods = doGoods::count('id');

        $user = doUser::count('id');

        $this->assign('cate',$cate);
        $this->assign('goods',$goods);
        $this->assign('admin',$admin);
        $this->assign('user',$user);

        $this->assign('admin_name',$this->admin['rel_name']);

        return $this->fetch();
    }
    public function errors()
    {
        return $this->fetch('error');
    }
    public function schoolrenzheng(){
        $cate = Db::name('cate')->where('id',$this->admin['school'])->find();
        $this->assign("cate",$cate);
        return $this->fetch('schoolrenzheng');
    }
    // 退出登录
    public function signOut()
    {
        Cookie::delete('admin');
        return $this->redirect('index/login/login');
    }
    //完善信息
    public function renzheng(){
        if(Request::isPost()){
            $data = input("post.");
            // dump($data);die;
            $if_re = Db::name("renzheng")->where('admin_id',$this->admin['id'])->find();
            if($if_re){
                ajaxMsg(0,'您已上传，请勿多次点击！如果页面没有刷新，请手动刷新页面');
            }
            // if(strtotime($data['work_etime'])<strtotime($data['work_stime'])){
            //     ajaxMsg(0,'教师工作年限有误');
            // }

            if(!in_array('无',$data['zhizheng'])){
                if(isset($data['zsfield'])){
                    if(count($data['zsfield'])==0){
                         ajaxMsg(0,'请上传证书文件！');
                    }
                }else{
                     ajaxMsg(0,'请上传证书文件！');
                }
            }
            if(isset($data['zsfield'])){
                $data['zsfield'] = json_encode($data['zsfield']);
                $data['zsop'] = json_encode($data['zsop']);
            }
            

            unset($data['aschool']);unset($data['file']);
            $w_time = strtotime($data['work_etime']).'-'.strtotime($data['work_stime']);
            
            $data['zhizheng'] = implode(',',$data['zhizheng']);

            
            $data['xueduan'] = json_encode($data['xueduan']);

            // $w_time = $this->Sec2Time($w_time);
            $data['ruzhi'] = $w_time;
            $data['admin_id'] = $this->admin['id'];

            $gongzuo = [];
            if(isset($data['w_stime'])){
                foreach ($data['w_stime'] as $key=>$val){
                    $gongzuo[$key]['w_stime'] = $val;
                    $gongzuo[$key]['w_etime'] = $data['w_etime'][$key];
                    if(isset($data['w_danwei'][$key]))$gongzuo[$key]['w_danwei'] = $data['w_danwei'][$key];
                    else $gongzuo[$key]['w_danwei'] = '空';
                    if(isset( $data['w_jingli'][$key]))$gongzuo[$key]['w_jingli'] = $data['w_jingli'][$key];
                    else $gongzuo[$key]['w_jingli'] = '空';
                }
                unset($data['w_stime']);unset($data['w_etime']);unset($data['w_danwei']);unset($data['w_jingli']);
        
                $data['work'] = json_encode($gongzuo);
            }
            $gongzuo = [];
            if(isset($data['p_stime'])){
                foreach ($data['p_stime'] as $key=>$val){
                    $gongzuo[$key]['p_stime'] = $val;
                    $gongzuo[$key]['p_etime'] = $data['p_etime'][$key];
                    if(isset($data['p_danwei'][$key]))$gongzuo[$key]['p_danwei'] = $data['p_danwei'][$key];
                    else $gongzuo[$key]['p_danwei'] = '空';
                    if(isset( $data['p_jingli'][$key]))$gongzuo[$key]['p_jingli'] = $data['p_jingli'][$key];
                    else $gongzuo[$key]['p_jingli'] = '空';
        
                }
                unset($data['p_stime']);unset($data['p_etime']);unset($data['p_danwei']);unset($data['p_jingli']);
                $data['peixun'] = json_encode($gongzuo);
                unset($data['nianxian']);
            }
            $baocun = input('baocun');
            if($baocun==1){
                $data['status'] = 1;
            }else{
                $data['status'] = 0;
            }

            $data['school'] = $this->admin['school'];
            $data['area'] = $this->admin['area'];
            $res = Db::name('renzheng')->insert($data);
            if($res){
                Db::name("admin")->where("id",$this->admin['id'])->update(['if_rz'=>1]);
                ajaxMsg(1,'提交成功,等待审批');
            }
                ajaxMsg(0,'网络延时稍后再试');
        }
        $admin = Db::name("admin")->where("id",$this->admin['id'])->find();
        // dump();
        $school = Db::name("cate")->where("id",$this->admin['school'])->find();
        $this->assign('school',$school);
        $area = Db::name("cate")->where("id",$this->admin['area'])->find();
        // dump($area);die;
        $this->assign('area',$area);
        $this->assign('admin',$admin);
        $cate = Db::name('cate')->where("status",1)->where('pid','1')->select();
        $this->assign('cate',$cate);
        $zs = Db::name("zhengshu")->where("status",1)->select();
        // dump($zs);die;
        $this->assign("zs",$zs);
        return $this->fetch();
    }
    public function baocun(){
         $data = input("post.");
            if(strtotime($data['work_etime'])<strtotime($data['work_stime'])){
                ajaxMsg(0,'教师工作年限有误');
            }
            if($data['schoolstyle']==2||$data['schoolstyle']==68){
                $data['area'] = $data['school'];
                $data['school'] = $data['aschool'];
                // unset($data['aschool']);
            }else{
                $data['area'] = 1;
            }
            if(isset($data['zsfield'])){
                $data['zsfield'] = json_encode($data['zsfield']);
                $data['zsop'] = json_encode($data['zsop']);
            }
            
            //unset($data['schoolstyle']);
            unset($data['aschool']);unset($data['file']);
            $w_time = strtotime($data['work_etime'])-strtotime($data['work_stime']);
            
            $data['zhizheng'] = json_encode($data['zhizheng']);
            // unset($data['work_stime']);unset($data['work_etime']);
            
            $data['xueduan'] = json_encode($data['xueduan']);
            // if(isset($data['other'])){
            //     $data['teacher'] .=$data['other'];
            // }
            $w_time = $this->Sec2Time($w_time);
            $data['ruzhi'] = $w_time;
            $data['admin_id'] = $this->admin['id'];
            $gongzuo = [];
            foreach ($data['t_stime'] as $key=>$val){
                $gongzuo[$key]['t_stime'] = $val;
                $gongzuo[$key]['t_etime'] = $data['t_etime'][$key];
            }
            unset($data['t_stime']);unset($data['t_etime']);
            $data['pwork'] = json_encode($gongzuo);
    
            $gongzuo = [];
            if(isset($data['w_stime'])){
                foreach ($data['w_stime'] as $key=>$val){
                    $gongzuo[$key]['w_stime'] = $val;
                    $gongzuo[$key]['w_etime'] = $data['w_etime'][$key];
                    if(isset($data['w_danwei'][$key]))$gongzuo[$key]['w_danwei'] = $data['w_danwei'][$key];
                    else $gongzuo[$key]['w_danwei'] = '空';
                    if(isset( $data['w_jingli'][$key]))$gongzuo[$key]['w_jingli'] = $data['w_jingli'][$key];
                    else $gongzuo[$key]['w_jingli'] = '空';
                }
                unset($data['w_stime']);unset($data['w_etime']);unset($data['w_danwei']);unset($data['w_jingli']);
        
                $data['work'] = json_encode($gongzuo);
            }
            
            $gongzuo = [];
            if(isset($data['p_stime'])){
                foreach ($data['p_stime'] as $key=>$val){
                    $gongzuo[$key]['p_stime'] = $val;
                    $gongzuo[$key]['p_etime'] = $data['p_etime'][$key];
                    if(isset($data['p_danwei'][$key]))$gongzuo[$key]['p_danwei'] = $data['p_danwei'][$key];
                    else $gongzuo[$key]['p_danwei'] = '空';
                    if(isset( $data['p_jingli'][$key]))$gongzuo[$key]['p_jingli'] = $data['p_jingli'][$key];
                    else $gongzuo[$key]['p_jingli'] = '空';
        
                }
                unset($data['p_stime']);unset($data['p_etime']);unset($data['p_danwei']);unset($data['p_jingli']);
                $data['peixun'] = json_encode($gongzuo);
                unset($data['nianxian']);
            }
            
    //        dump($data);die;
            $data['status'] = 0;
            $data['school'] = $this->admin['school'];
            $adta['area'] = $this->admin['area'];
            // $data['school_type'] = $this->admin['school_type'];
            
            $res = Db::name('renzheng')->insert($data);
            if($res){
                Db::name("admin")->where("id",$this->admin['id'])->update(['if_rz'=>1]);
                ajaxMsg(1,'提交成功,等待审批');
            }
                ajaxMsg(0,'网络延时稍后再试');
    }
    //上传头像
    public function uploadimg(){
        $file = request()->file('file');
        $res = Upload($file,['ext' =>'jpg,png,jpeg,bmp,tiff,svg,webp,gif'],'/uploads/banner/');
//        filePath
        ajaxMsg(1,$res['filePath']);
    }
    public function uploadfield(){
        $file = request()->file('file');
        $res = Upload($file,[],'/uploads/field/');
//        filePath
        ajaxMsg(1,$res['filePath']);
    }
    private function Sec2Time($time){
        if(is_numeric($time)){
            $value = array(
                "years" => 0, "days" => 0, "hours" => 0,
                "minutes" => 0, "seconds" => 0,
            );
            if($time >= 31556926){
                $value["years"] = floor($time/31556926);
                $time = ($time%31556926);
            }
            if($time >= 86400){
                $value["days"] = floor($time/86400);
                $time = ($time%86400);
            }
            if($time >= 3600){
                $value["hours"] = floor($time/3600);
                $time = ($time%3600);
            }
            if($time >= 60){
                $value["minutes"] = floor($time/60);
                $time = ($time%60);
            }
            $value["seconds"] = floor($time);
            //return (array) $value;
            $t=$value["years"] ."年". $value["days"] ."天"." ". $value["hours"] ."小时". $value["minutes"] ."分".$value["seconds"]."秒";
            Return $t;

        }else{
            return (bool) FALSE;
        }
    }
    public function renzhengsubmit(){

        $data = input("post.");
//        dump($data);die;
        unset($data['file']);
        //功能教室
        $gongneng =[];
        foreach($data['gongnengname'] as $key=>$val){
                $gongneng[$key]['name'] = $val;
                if(!isset($data['gongneng'][$key])){
                    ajaxMsg(0,'请填写面积');
                }
                $gongneng[$key]['mianji'] = $data['gongneng'][$key];
                $gongneng[$key]['num'] = $data['gongnengnum'][$key];
            }
            unset($data['gongnengname']);unset($data['gongnengnum']);

        $data['gongneng'] = json_encode($gongneng);
        //课程信息
        $class = [];
        foreach($data['class_name'] as $key=>$val){
            $class[$key]['name'] = $val;
            if(!isset($data['class_time'][$key])||!isset($data['class_type'][$key])||!isset($data['class_teacher'][$key])||!isset($data['class_info'][$key])){
                ajaxMsg(0,'请补全课程信息');
            }
            $class[$key]['times'] = $data['class_time'][$key];
            $class[$key]['type'] = $data['class_type'][$key];
            $class[$key]['teacher'] = $data['class_teacher'][$key];
            $class[$key]['info'] = $data['class_info'][$key];
        }
        unset($data['class_time']);unset($data['class_type']);unset($data['class_teacher']);unset($data['class_info']);unset($data['class_name']);
        $data['class_info'] = json_encode($class);
        //专职老师信息
        // $teacher = [];
        // foreach($data['teacher_name'] as $key=>$val){
        //     $teacher[$key]['name'] = $val;
        //     if(!isset($data['teacher_sex'][$key])||!isset($data['teacher_year'][$key])||!isset($data['work_stime'][$key])||!isset($data['work_etime'][$key])||!isset($data['teacher_zhizheng'][$key])){
        //         ajaxMsg(0,'请补全老师信息');
        //     }
        //     $teacher[$key]['sex'] = $data['teacher_sex'][$key];
        //     $teacher[$key]['year'] = $data['teacher_year'][$key];

        //     if(strtotime($data['work_etime'][$key])<strtotime($data['work_stime'][$key])){
        //         ajaxMsg(0,'教师工作年限有误');
        //     }
        //     $teacher[$key]['work'] = $this->Sec2Time(strtotime($data['work_etime'][$key])-strtotime($data['work_stime'][$key]));
        //     $teacher[$key]['field'] = $data['teach_field'][$key];
        //     $teacher[$key]['zhizheng'] = $data['teacher_zhizheng'][$key];
        // }
        // unset($data['teacher_name']);unset($data['teacher_sex']);unset($data['teacher_year']);unset($data['work_stime']);unset($data['work_etime']);
        // unset($data['teacher_zhizheng']);unset($data['teach_field']);
        $data['teacher_info'] = json_encode($teacher);
        $data['admin_id'] = $this->admin['id'];
        $data['status'] = 1;
        $data['time'] = time();
        $res = Db::name('school_renzheng')->insert($data);
        if($res){
            ajaxMsg(1,'提交成功,等待审批');
        }
        ajaxMsg(0,'网络延时稍后再试');
    }
    public function changepassword(){
        if(Request::isPost()){
            $data = input('post.');
            $data['password'] = sha1($data['pass']);
            unset($data['pass']);
            $data['first'] =1;
            $this->admin['first'] =1;
            $res = Db::name("admin")->where("id",$this->admin['id'])->update($data);
            if($res){
                ajaxMsg('1','修改成功');
            }
            ajaxMsg('0','密码没有变化！！');
        }
        $this->assign('admin',$this->admin);
        return $this->fetch();
    }
    public function uploadschool(){
        $type = input('type');
        $file = $_FILES['file'];
        if ($file['error'] == 4) $this->error('请选择上传excel文件');
        $file_types = explode ( ".", $file['name'] );
        $excel_type = array('xls','csv','xlsx','xlsxla');
        if (!in_array(strtolower(end($file_types)),$excel_type)){
            $this->error("不是Excel文件，请重新上传");
        }

        include(getcwd()."/../vendor/PHPExcel/PHPExcel.php");

        if (end($file_types) =='xlsx') {
            $objReader = new \PHPExcel_Reader_Excel2007();
            $objPHPExcel = $objReader ->load($file['tmp_name']);
        } else if (end($file_types) =='xls') {
            $objReader = new \PHPExcel_Reader_Excel5();
            $objPHPExcel = $objReader ->load($file['tmp_name']);
        } else if (end($file_types)=='csv') {
            $PHPReader = new \PHPExcel_Reader_CSV();

            //默认输入字符集
            $PHPReader->setInputEncoding('GBK');

            //默认的分隔符
            $PHPReader->setDelimiter(',');

            //载入文件
            $objPHPExcel = $PHPReader->load($file['tmp_name']);
        }
        $admin = $this->admin;
        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow(); // 取得总行数
        //教育局添加所属学校
        if($type==3){
            Db::startTrans();
            try{
                //开始读取数据
                for($j=2;$j<=$highestRow;$j++)
                {
                    $title = $objPHPExcel->getActiveSheet()->getCell('B'.$j)->getValue();
                    if(!$title ){
                        continue;
                    }
                    $if_exit = Db::name("cate")->where("title",$title)->find();
                    if($if_exit){
                        Db::rollback();
                        ajaxMsg(0,'学校名称已存在！重复项：'.$title);
                    }
                    $cate['title'] = $title;
                    $cate['pid'] = $admin['area'];
                    $cate['status'] = 1;
                    $cate['lv'] = 3;
                    //添加分类
                    $id = DB::name("cate")->insertGetId($cate);
                    
                    //添加对应管理员
                    $admin_data['rid'] = 8;//学校权限
                    $admin_data['name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//姓名
                    
                    $admin_data['idcard'] = 'SH'.trim($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue());//身份证
                    $admin_data['password'] = sha1(substr($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue(),-6));//密码
                    $admin_data['status'] = 1;
                    $admin_data['time'] = time();
                    $admin_data['rel_name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//真实姓名
                    $admin_data['phone'] =  $objPHPExcel->getActiveSheet()->getCell('E'.$j)->getValue();//手机号
                    $admin_data['bumen'] =  $objPHPExcel->getActiveSheet()->getCell('F'.$j)->getValue();//所在部门
                    $admin_data['school'] = $id;//学校分类id
                    $admin_data['area'] = $this->admin['area'];//所属教育局
                    $admin_data['email'] = ' ';//所属教育局
                    $admin_data['lv'] = 3;//等级为学校等级
                    Db::name('admin')->insert($admin_data);
                    Db::name('admin')->where('id',$admin['id'])->update(['first'=>2]);
                }
                Db::commit();
            }catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                dump($e);
            }
            ajaxMsg('1','导入成功');
        }elseif($type==1){
        
            Db::startTrans();
            try{
                //开始读取数据
                for($j=2;$j<=$highestRow;$j++)
                {
                    //查询区分类
                    $area =$this->admin['area'];
                    
                    $cate['title'] = $objPHPExcel->getActiveSheet()->getCell('B'.$j)->getValue();//所在机构
                    if(!$cate['title'] ){
                        continue;
                    }
                    $if_exit = Db::name("cate")->where("title",$cate['title'])->find();
                    if($if_exit){
                        Db::rollback();
                        ajaxMsg(0,'学校名称已存在！重复项：'.$cate['title']);
                    }
                    $cate['pid'] = $area;
                    $cate['status'] = 1;
                    $cate['lv'] = 3;
                    // dump($cate);die;
                    //添加分类
                    $id = DB::name("cate")->insertGetId($cate);
                    //添加对应管理员
                    $admin_data['rid'] = 8;//学校权限
                    $admin_data['name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//姓名
                    
                    $admin_data['idcard'] = 'SH'.trim($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue());//身份证
                    $admin_data['password'] = sha1(substr($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue(),-6));//密码
                    $admin_data['status'] = 1;
                    $admin_data['time'] = time();
                    $admin_data['rel_name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//真实姓名
                    $admin_data['phone'] =  $objPHPExcel->getActiveSheet()->getCell('E'.$j)->getValue();//手机号
                    $admin_data['bumen'] =  $objPHPExcel->getActiveSheet()->getCell('F'.$j)->getValue();//所在部门
                    $admin_data['school'] = $id;//学校分类id
                    $admin_data['area'] = $area;//所属教育局
                    $admin_data['email'] = ' ';//所属教育局
                    $admin_data['lv'] = 3;//等级为学校等级
                    Db::name('admin')->insert($admin_data);
                    Db::name('admin')->where('id',$admin['id'])->update(['first'=>2]);
                }
                Db::commit();
            }catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                dump($e);
            }
            ajaxMsg('1','导入成功');
        }else if($type==2){//中心添加直属校
            Db::startTrans();
            try{
                //开始读取数据
                for($j=2;$j<=$highestRow;$j++)
                {
                    $area =2;
                    $cate['title'] = $objPHPExcel->getActiveSheet()->getCell('B'.$j)->getValue();
                    if(!$cate['title'] ){
                        continue;
                    }
                    $if_exit = Db::name("cate")->where("title",$cate['title'])->find();
                    if($if_exit){
                        Db::rollback();
                        ajaxMsg(0,'学校名称已存在！重复项：'.$cate['title']);
                    }
                    $cate['pid'] = $area;
                    $cate['status'] = 1;
                    $cate['lv'] = 3;
                    //添加分类
                    $id = DB::name("cate")->insertGetId($cate);
                    //添加对应管理员
                    $admin_data['rid'] = 8;//学校权限
                    $admin_data['name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//姓名
                    $admin_data['idcard'] = 'SH'.trim($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue());//电话
                    $admin_data['password'] = sha1(substr($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue(),-6));//密码
                    $admin_data['status'] = 1;
                    $admin_data['time'] = time();
                    $admin_data['rel_name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();
                    $admin_data['phone'] =  $objPHPExcel->getActiveSheet()->getCell('E'.$j)->getValue();
                    $admin_data['bumen'] =  $objPHPExcel->getActiveSheet()->getCell('F'.$j)->getValue();
                    $admin_data['school'] = $id;//学校分类id
                    $admin_data['area'] = $area;//所属教育局
                    $admin_data['email'] = ' ';//所属教育局
                    $admin_data['lv'] = 3;//等级为学校等级
                    Db::name('admin')->insert($admin_data);
                    // dump($admin_data);
                    Db::name('admin')->where('id',$admin['id'])->update(['first'=>2]);
                }
                Db::commit();
            }catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                dump($e);
            }
            ajaxMsg('1','导入成功');
        }else if($type ==4){//中心导入教育局账号
            //  Db::startTrans();
            // try{
            //     //开始读取数据
                for($j=2;$j<=$highestRow;$j++)
                {
                    // $area = 1;
                    $cate['title'] = $objPHPExcel->getActiveSheet()->getCell('B'.$j)->getValue();
                    if(!$cate['title'] ){
                        continue;
                    }
                    $if_exit = Db::name("cate")->where("title",$cate['title'])->find();
                    if($if_exit){
                        Db::rollback();
                        ajaxMsg(0,'教育局名称已存在！重复项：'.$cate['title']);
                    }
                    $cate['pid'] = 1;
                    $cate['status'] = 1;
                    $cate['lv'] = 2;
                    //   dump($cate);die;
                    //添加分类
                    $id = DB::name("cate")->insertGetId($cate);
                    //添加对应管理员
                    $admin_data['rid'] = 9;//教育局权限
                    $admin_data['name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();//姓名
                    $admin_data['idcard'] = 'SH'.trim($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue());//电话
                    $admin_data['password'] = sha1(substr($objPHPExcel->getActiveSheet()->getCell('D'.$j)->getValue(),-6));//密码
                    $admin_data['status'] = 1;
                    $admin_data['time'] = time();
                    $admin_data['rel_name'] = $objPHPExcel->getActiveSheet()->getCell('C'.$j)->getValue();
                    $admin_data['phone'] =  $objPHPExcel->getActiveSheet()->getCell('E'.$j)->getValue();
                    $admin_data['bumen'] =  $objPHPExcel->getActiveSheet()->getCell('F'.$j)->getValue();
                    $admin_data['school'] = '';//学校分类id
                    $admin_data['area'] = $id;//所属教育局
                    $admin_data['email'] = ' ';//所属教育局
                    $admin_data['lv'] = 2;//等级为教育局
                    // dump($admin_data);die;
                    Db::name('admin')->insert($admin_data);
                    // dump($admin_data);
                    // Db::name('admin')->where('id',$admin['id'])->update(['first'=>2]);
                }
            //     Db::commit();
            // }catch (\Exception $e) {
            //     // 回滚事务
            //     Db::rollback();
            //     dump($e);
            // }
            ajaxMsg('1','导入成功');
        }
    }
    
 
}
